<?php
function check_chinayear ($y, $num)
{
    $oo = array(array(1, 13, 25, 37, 49), array(12, 24, 36, 48), array(11, 23, 35, 47), array(10, 22, 34, 46), array(9, 21, 33, 45), array(8, 20, 32, 44), array(7, 19, 31, 43), array(6, 18, 30, 42), array(5, 17, 29, 41), array(4, 16, 28, 40), array(3, 15, 27, 39), array(2, 14, 26, 38));
    $k = 0;
    $g = array();
    $i = $y;
    while ($i <= 12)
    {
        $g[$i] = $oo[$k++];
        ++$i;
    }
    $i = 1;
    while ($i < $y)
    {
        $g[$i] = $oo[$k++];
        ++$i;
    }
    $i = 1;
    while ($i <= 12)
    {
        if (in_array($num, $g[$i]))
        {
            return $i;
        }
        ++$i;
    }
    return 0 - 0.001;
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$ui = new UI();
$user = new User();
$tpl = new Template2();
$tpl->load(array("menu" => "6h_menu.htm","main" => "result.htm", "news" => "news.htm", "live" => "live.htm"));
$tpl->show( "menu" );
$conf = new Config();
$news = $conf->Get("news");
$tpl->set("newsmessage", $news);
$color = array("", "red", "blue", "green");
$oddname = array(0 => "和", 1 => "<font color='#BB00AA'>单", 2 => "<font color='#0077AA'>双");
$bigname = array(0 => "和", 1 => "<font color='#BB00AA'>大", 2 => "<font color='#0077AA'>小", 3 => "<font color='chocolate'>中");
$chinayear = array("", "<font color='#BB00AA'>鼠", "<font color='#0077AA'>牛</font>", "<font color='#BB00AA'>虎", "<font color='#BB00AA'>兔", "<font color='#BB00AA'>龙", "<font color='#BB00AA'>蛇", "<font color='#0077AA'>马</font>", "<font color='#0077AA'>羊</font>", "<font color='#BB00AA'>猴", "<font color='#0077AA'>鸡</font>", "<font color='#0077AA'>狗</font>", "<font color='#0077AA'>猪</font>");
$list = "";
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
if ($page == 0)
{
    $page = 1;
}
$pagesize = 15;

$rs1 = getdb("select * from lotto where open <= '" . date("Y-m-d") . "' order by open desc", $page, $pagesize);
while (!$rs1->eof)
{
    $list .= "<tr class=td2>";
    $list .= "<td class=td15>" . d3($rs1->f['round']) . "</td>";
    $t = strtotime($rs1->f['open']);
    $list .= "<td align=center>" . $g_weekname[date("w", $t)] . "</td>";
    $list .= "<td nowrap=\"nowrap\" align=\"center\">" . $rs1->f['open'] . "</td>";
    $cyear = $rs1->f['cyear'];
    if ($rs1->f['total'] == 0)
    {
        $list .= "<td></td><td></td><td></td><td></td><td></td><td></td>";
        $list .= "<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>";
        $list .= "<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>";
    }
    else
    {
        $onec = array();
        $i = 1;
        while ($i <= 6)
        {
            $list .= "<td class=ball" . $color[$g_numcolor[$rs1->f["n" . $i]]] . ">" . $rs1->f["n" . $i] . "</td>";
            $onecc = $chinayear[check_chinayear($cyear, $rs1->f["n" . $i])];
            $onec[] = $onecc;
            ++$i;
        }
        $list .= "<td class=ball" . $color[$g_numcolor[$rs1->f['spec']]] . ">" . $rs1->f['spec'] . "</td>";
        $s_total = substr(d2($rs1->f['spec']), 0, 1) + substr(d2($rs1->f['spec']), 0 - 1);
        if ($s_total < 13 && 6 < $s_total)
        {
            $spec_total = $bigname[1];
        }
        else if ($s_total < 7 && 0 < $s_total)
        {
            $spec_total = $bigname[2];
        }
        else if ($s_total == 13)
        {
            $spec_total = $bigname[0];
        }
        else
        {
            $spec_total = "";
        }
        $list .= "<td align=center>" . $oddname[$rs1->f['p1']] . "</font></td>";
        $list .= "<td align=center>" . $bigname[$rs1->f['p2']] . "</font></td>";
        $list .= "<td align=right>" . $rs1->f['total'] . "</td>";
        $list .= "<td align=center>" . $oddname[$rs1->f['p3']] . "</font></td>";
        $list .= "<td align=center>" . $bigname[$rs1->f['p4']] . "</font></td>";
        $list .= "<td align=center>" . $chinayear[$rs1->f['p5']] . "</font></td>";
        $list .= "<td align=center>" . $oddname[$rs1->f['p6']] . "</font></td>";
        $list .= "<td align=center>" . $spec_total . "</font></td>";
        $cc = 0;
        while ($cc < count($onec))
        {
            $list .= "<td>" . $onec[$cc] . "</td>";
            ++$cc;
        }
        $list .= "<td class=" . $color[$rs1->f['p7']] . " align=center>" . $g_colorname[$rs1->f['p7']] . "</td>";
    }
    $list .= "</tr>\n";
    $rs1->movenext();
}
$list .= "<tr><td colspan=26 class=td0>" . $rs1->pagelink() . "</td></tr>";
$tpl->set("list", $list);
$tpl->show("news");
$round = show_live($conf);
if ($round)
{
    $tpl->load("live", "live.htm");
    $tpl->set("round", d3($round));
    $tpl->set("livehtml", $tpl->parse("live"));
}
$tpl->show("main");
$ui->footer();
?>